<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>Dissasemble: src/process/elfProcess/elfProcess.c Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  <td id="projectlogo"><img alt="Logo" src="Hopper_v3.png"/></td>
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">Dissasemble
   &#160;<span id="projectnumber">1.0</span>
   </div>
   <div id="projectbrief">This project receives as input a file.o and displays the assembly code for that object.</div>
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.6.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>Globals</span></a></li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('elf_process_8c.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">src/process/elfProcess/elfProcess.c</div>  </div>
</div><!--header-->
<div class="contents">
<a href="elf_process_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment"> ============================================================================</span>
<a name="l00003"></a>00003 <span class="comment"> Name        : elfProcess.c</span>
<a name="l00004"></a>00004 <span class="comment"> Author      :</span>
<a name="l00005"></a>00005 <span class="comment"> Version     :  1</span>
<a name="l00006"></a>00006 <span class="comment"> Copyright   : Your copyright notice</span>
<a name="l00007"></a>00007 <span class="comment"> Description : Process to identifies the elf headers and the different section of the input file</span>
<a name="l00008"></a>00008 <span class="comment"> ============================================================================</span>
<a name="l00009"></a>00009 <span class="comment"> */</span>
<a name="l00010"></a>00010 
<a name="l00011"></a>00011 <span class="preprocessor">#include &quot;<a class="code" href="elf_process_8h.html">elfProcess.h</a>&quot;</span>
<a name="l00012"></a>00012 
<a name="l00013"></a>00013 <span class="preprocessor">#include &lt;libelf.h&gt;</span>
<a name="l00014"></a>00014 <span class="preprocessor"># include &lt;err.h&gt;</span>
<a name="l00015"></a>00015 <span class="preprocessor"># include &lt;fcntl.h&gt;</span>
<a name="l00016"></a>00016 <span class="preprocessor"># include &lt;libelf.h&gt;</span>
<a name="l00017"></a>00017 <span class="preprocessor"># include &lt;stdio.h&gt;</span>
<a name="l00018"></a>00018 <span class="preprocessor"># include &lt;stdlib.h&gt;</span>
<a name="l00019"></a>00019 <span class="preprocessor"># include &lt;unistd.h&gt;</span>
<a name="l00020"></a>00020 <span class="preprocessor">#include &lt;assert.h&gt;</span>
<a name="l00021"></a>00021 
<a name="l00022"></a><a class="code" href="elf_process_8c.html#aa669cc9790fbafeb364cbe10641c172d">00022</a> <span class="preprocessor">#define PRINT_FMT       &quot;%-20s 0x%jx\n&quot; ///&lt;Sets the output format screen attributes ELF header</span>
<a name="l00023"></a>00023 <span class="preprocessor"></span>
<a name="l00024"></a>00024 <span class="keywordtype">void</span> <a class="code" href="elf_process_8c.html#a349bf83f64825eff7c81cd30ce65bdca" title="Displays the ELF file characteristics established in its header.">ReadingELFExecutableHeader</a>(Elf *e, <span class="keywordtype">int</span> <a class="code" href="my_obj_dump_8c.html#a6f8059414f0228f0256115e024eeed4b" title="Pointer to binary file.">fd</a>);
<a name="l00025"></a>00025 <span class="comment">//char rawPrint(unsigned char* buffer, unsigned long size)</span>
<a name="l00030"></a><a class="code" href="elf_process_8h.html#a31a949c6084b36717e5995d46a7082e5">00030</a> <span class="comment"></span><span class="keywordtype">char</span> <a class="code" href="elf_process_8c.html#af621c30c7fe80118c18f9bb317f0b95a" title="Print of display file content on hex.">rawPrint</a>(<span class="keywordtype">int</span> <a class="code" href="my_obj_dump_8c.html#a6f8059414f0228f0256115e024eeed4b" title="Pointer to binary file.">fd</a>)
<a name="l00031"></a>00031 {
<a name="l00032"></a>00032 
<a name="l00033"></a>00033         printf(<span class="stringliteral">&quot;-------------------------\n&quot;</span>);
<a name="l00034"></a>00034         printf(<span class="stringliteral">&quot;        DUMP HEX\n&quot;</span>);
<a name="l00035"></a>00035         printf(<span class="stringliteral">&quot;-------------------------\n&quot;</span>);
<a name="l00036"></a>00036         printf(<span class="stringliteral">&quot;ADDRESS :  [    DATA    ]\n&quot;</span>);
<a name="l00037"></a>00037         <span class="keywordtype">int</span> pos = 0;
<a name="l00038"></a>00038 
<a name="l00039"></a>00039         <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> buf[4];
<a name="l00040"></a>00040         <span class="keywordflow">while</span> (read(fd, &amp;buf, 4))
<a name="l00041"></a>00041         {
<a name="l00042"></a>00042                 printf(<span class="stringliteral">&quot;%08x: &quot;</span>, pos);
<a name="l00043"></a>00043                 printf(<span class="stringliteral">&quot; %02x &quot;</span>, buf[0]);
<a name="l00044"></a>00044                 printf(<span class="stringliteral">&quot; %02x &quot;</span>, buf[1]);
<a name="l00045"></a>00045                 printf(<span class="stringliteral">&quot; %02x &quot;</span>, buf[2]);
<a name="l00046"></a>00046                 printf(<span class="stringliteral">&quot; %02x\n&quot;</span>, buf[3]);
<a name="l00047"></a>00047                 pos += 4;
<a name="l00048"></a>00048         }
<a name="l00049"></a>00049 
<a name="l00050"></a>00050         <span class="keywordflow">return</span> <a class="code" href="debug_8h.html#ae56fdb340b23940f7a64ed2e37c1774a" title="Response code when a process has performed an error in its execution.">STATUS_SUCCESS</a>;
<a name="l00051"></a>00051 }
<a name="l00058"></a><a class="code" href="elf_process_8c.html#a309cc9f8f31dc406fbd4f950f14c9e85">00058</a> <span class="keywordtype">char</span> <a class="code" href="elf_process_8c.html#a309cc9f8f31dc406fbd4f950f14c9e85" title="Validate if the input file is an elf object.">validateElf</a>(Elf** source, <span class="keywordtype">int</span> <a class="code" href="my_obj_dump_8c.html#a6f8059414f0228f0256115e024eeed4b" title="Pointer to binary file.">fd</a>, <span class="keywordtype">size_t</span> *shstrndx)
<a name="l00059"></a>00059 {
<a name="l00060"></a>00060         Elf * e = 0;
<a name="l00061"></a>00061 
<a name="l00062"></a>00062         <span class="comment">//A call to elf version is mandatory before other functions in the ELF library can be invoked</span>
<a name="l00063"></a>00063         <span class="keywordflow">if</span> (elf_version(EV_CURRENT) == EV_NONE)
<a name="l00064"></a>00064         {
<a name="l00065"></a>00065                 <a class="code" href="debug_8c.html#a8ded31085b483d44dbeb3adbecd2debf" title="Displays the error message.">PRINT_ERROR</a>(<span class="stringliteral">&quot;Elf lib initialization \n&quot;</span>);
<a name="l00066"></a>00066                 <span class="keywordflow">return</span> <a class="code" href="debug_8h.html#ae4a97f0d170bc8dc771aac6c4f38ad1d" title="Response code when a process was run efficiently.">STATUS_ERROR</a>;
<a name="l00067"></a>00067         }
<a name="l00068"></a>00068         <span class="comment">//elf_begin()takes an open file descriptor and converts it an Elf handle according to the command specified (ELF_C_READ).</span>
<a name="l00069"></a>00069         <span class="keywordflow">if</span> ((e = elf_begin(fd, ELF_C_READ, NULL )) == NULL )
<a name="l00070"></a>00070         {
<a name="l00071"></a>00071                 <a class="code" href="debug_8c.html#a8ded31085b483d44dbeb3adbecd2debf" title="Displays the error message.">PRINT_ERROR</a>(<span class="stringliteral">&quot;Elf begin failed \n&quot;</span>);
<a name="l00072"></a>00072                 <span class="keywordflow">return</span> <a class="code" href="debug_8h.html#ae4a97f0d170bc8dc771aac6c4f38ad1d" title="Response code when a process was run efficiently.">STATUS_ERROR</a>;
<a name="l00073"></a>00073         }
<a name="l00074"></a>00074         <span class="comment">//elf_kind() returns the kind of object associated with an Elf han-dle.</span>
<a name="l00075"></a>00075         <span class="keywordflow">if</span> (elf_kind(e) != ELF_K_ELF)
<a name="l00076"></a>00076         {
<a name="l00077"></a>00077                 <a class="code" href="debug_8c.html#a8ded31085b483d44dbeb3adbecd2debf" title="Displays the error message.">PRINT_ERROR</a>(<span class="stringliteral">&quot;Is not an ELF object\n&quot;</span>);
<a name="l00078"></a>00078                 <span class="keywordflow">return</span> <a class="code" href="debug_8h.html#ae4a97f0d170bc8dc771aac6c4f38ad1d" title="Response code when a process was run efficiently.">STATUS_ERROR</a>;
<a name="l00079"></a>00079         }
<a name="l00080"></a>00080 <span class="comment">//elf getshdrstrndx() allows our program to work correctly when the object being examined has a very large number of sections.</span>
<a name="l00081"></a>00081 
<a name="l00082"></a>00082         <span class="keywordflow">if</span> (elf_getshdrstrndx(e, shstrndx) != 0)
<a name="l00083"></a>00083         {
<a name="l00084"></a>00084                 <a class="code" href="debug_8c.html#a8ded31085b483d44dbeb3adbecd2debf" title="Displays the error message.">PRINT_ERROR</a>(<span class="stringliteral">&quot;Fail getting the header\n&quot;</span>);
<a name="l00085"></a>00085                 <span class="keywordflow">return</span> <a class="code" href="debug_8h.html#ae4a97f0d170bc8dc771aac6c4f38ad1d" title="Response code when a process was run efficiently.">STATUS_ERROR</a>;
<a name="l00086"></a>00086         }
<a name="l00087"></a>00087 
<a name="l00088"></a>00088         *source = e;
<a name="l00089"></a>00089         <span class="keywordflow">return</span> <a class="code" href="debug_8h.html#ae56fdb340b23940f7a64ed2e37c1774a" title="Response code when a process has performed an error in its execution.">STATUS_SUCCESS</a>;
<a name="l00090"></a>00090 }
<a name="l00098"></a><a class="code" href="elf_process_8c.html#adaf709c5598ed900ab21942a1e55dc32">00098</a> <span class="keywordtype">void</span> <a class="code" href="elf_process_8c.html#adaf709c5598ed900ab21942a1e55dc32" title="Prints section data.">print_symbols</a>(Elf *elf, Elf_Scn *scn, GElf_Shdr *shdr)
<a name="l00099"></a>00099 {
<a name="l00100"></a>00100         Elf_Data *data;
<a name="l00101"></a>00101         <span class="keywordtype">char</span> *name;
<a name="l00102"></a>00102 
<a name="l00103"></a>00103         data = 0;
<a name="l00104"></a>00104         <span class="keywordtype">int</span> number = 0;
<a name="l00105"></a>00105         <span class="comment">//Elf Data descriptors associated with the section in   question, verifies if the section has data</span>
<a name="l00106"></a>00106         <span class="keywordflow">if</span> ((data = elf_getdata(scn, data)) == 0 || data-&gt;d_size == 0)
<a name="l00107"></a>00107         {
<a name="l00108"></a>00108                 <span class="comment">/* error or no data */</span>
<a name="l00109"></a>00109                 fprintf(stderr, <span class="stringliteral">&quot;Section had no data!n&quot;</span>);
<a name="l00110"></a>00110                 <span class="comment">//exit(-1);</span>
<a name="l00111"></a>00111         }
<a name="l00112"></a>00112         <span class="comment">/*now print the symbols*/</span>
<a name="l00113"></a>00113         Elf32_Sym *esym = (Elf32_Sym*) data-&gt;d_buf;
<a name="l00114"></a>00114         Elf32_Sym *lastsym = (Elf32_Sym*) ((<span class="keywordtype">char</span>*) data-&gt;d_buf + data-&gt;d_size);
<a name="l00115"></a>00115         <span class="comment">/* now loop through the symbol table and print it*/</span>
<a name="l00116"></a>00116         <span class="keywordflow">for</span> (; esym &lt; lastsym; esym++)
<a name="l00117"></a>00117         {
<a name="l00118"></a>00118                 <span class="keywordflow">if</span> ((esym-&gt;st_value == 0) || (ELF32_ST_BIND(esym-&gt;st_info) == STB_WEAK)
<a name="l00119"></a>00119                                 || (ELF32_ST_BIND(esym-&gt;st_info) == STB_NUM)
<a name="l00120"></a>00120                                 || (ELF32_ST_TYPE(esym-&gt;st_info) != STT_FUNC))
<a name="l00121"></a>00121                         <span class="keywordflow">continue</span>;
<a name="l00122"></a>00122                 name = elf_strptr(elf, shdr-&gt;sh_link, (<span class="keywordtype">size_t</span>) esym-&gt;st_name);
<a name="l00123"></a>00123                 <span class="keywordflow">if</span> (!name)
<a name="l00124"></a>00124                 {
<a name="l00125"></a>00125                         fprintf(stderr, <span class="stringliteral">&quot;%sn&quot;</span>, elf_errmsg(elf_errno()));
<a name="l00126"></a>00126                         <span class="comment">//exit(-1);</span>
<a name="l00127"></a>00127                 }
<a name="l00128"></a>00128                 printf(<span class="stringliteral">&quot;%d: %sn&quot;</span>, number++, name);
<a name="l00129"></a>00129         }
<a name="l00130"></a>00130 }
<a name="l00131"></a>00131 
<a name="l00136"></a><a class="code" href="elf_process_8h.html#a1910160c9bc9f2972b824c3ec93273b2">00136</a> <span class="keywordtype">char</span> <a class="code" href="elf_process_8c.html#afc812de68f9f038283aacfdeead056d1" title="Prints on display the ELF headers of the input file.">printHeaders</a>(<span class="keywordtype">int</span> <a class="code" href="my_obj_dump_8c.html#a6f8059414f0228f0256115e024eeed4b" title="Pointer to binary file.">fd</a>)
<a name="l00137"></a>00137 {
<a name="l00138"></a>00138 
<a name="l00139"></a>00139         Elf * e = 0;
<a name="l00140"></a>00140         <span class="keywordtype">char</span> * name;
<a name="l00141"></a>00141         Elf_Scn * scn;
<a name="l00142"></a>00142         GElf_Shdr shdr;
<a name="l00143"></a>00143         <span class="keywordtype">size_t</span> shstrndx;
<a name="l00144"></a>00144 
<a name="l00145"></a>00145         <a class="code" href="elf_process_8c.html#a309cc9f8f31dc406fbd4f950f14c9e85" title="Validate if the input file is an elf object.">validateElf</a>(&amp;e, fd, &amp;shstrndx);
<a name="l00146"></a>00146         <a class="code" href="elf_process_8c.html#a349bf83f64825eff7c81cd30ce65bdca" title="Displays the ELF file characteristics established in its header.">ReadingELFExecutableHeader</a>(e, fd);
<a name="l00147"></a>00147         scn = NULL;
<a name="l00148"></a>00148 
<a name="l00149"></a>00149         <span class="keywordflow">while</span> ((scn = elf_nextscn(e, scn)) != NULL )
<a name="l00150"></a>00150         {
<a name="l00151"></a>00151                 <span class="keywordflow">if</span> (gelf_getshdr(scn, &amp;shdr) != &amp;shdr)
<a name="l00152"></a>00152                 {
<a name="l00153"></a>00153                         <a class="code" href="debug_8c.html#a8ded31085b483d44dbeb3adbecd2debf" title="Displays the error message.">PRINT_ERROR</a>(<span class="stringliteral">&quot;getshdr () failed : % s . &quot;</span>, elf_errmsg(-1));
<a name="l00154"></a>00154                         <span class="keywordflow">return</span> <a class="code" href="debug_8h.html#ae4a97f0d170bc8dc771aac6c4f38ad1d" title="Response code when a process was run efficiently.">STATUS_ERROR</a>;
<a name="l00155"></a>00155                 }
<a name="l00156"></a>00156 
<a name="l00157"></a>00157                 <span class="comment">//print_symbols(e,scn,&amp;shdr);</span>
<a name="l00158"></a>00158                 <span class="keywordflow">if</span> ((name = elf_strptr(e, shstrndx, shdr.sh_name)) == NULL )
<a name="l00159"></a>00159                 {
<a name="l00160"></a>00160                         <a class="code" href="debug_8c.html#a8ded31085b483d44dbeb3adbecd2debf" title="Displays the error message.">PRINT_ERROR</a>(<span class="stringliteral">&quot;elf_strptr () failed : % s . &quot;</span>, elf_errmsg(-1));
<a name="l00161"></a>00161                 }
<a name="l00162"></a>00162 
<a name="l00163"></a>00163                 <span class="comment">//printf(&quot;Section: %x, %s\n&quot;, (unsigned int) elf_ndxscn(scn), name);</span>
<a name="l00164"></a>00164                 <span class="comment">//(void) printf(&quot; Section % -4.4 jd % s \ n &quot;, (uintmax_t) elf_ndxscn(scn), name);</span>
<a name="l00165"></a>00165         }
<a name="l00166"></a>00166 
<a name="l00167"></a>00167         <span class="keywordflow">return</span> <a class="code" href="debug_8h.html#ae56fdb340b23940f7a64ed2e37c1774a" title="Response code when a process has performed an error in its execution.">STATUS_SUCCESS</a>;
<a name="l00168"></a>00168 }
<a name="l00173"></a><a class="code" href="elf_process_8h.html#afd9f673411d8fb30767b69b55b9ef617">00173</a> <span class="keywordtype">char</span> <a class="code" href="elf_process_8c.html#a322e41fb93d676b56ecc10f3ca833054" title="Process ELF headers of the input file.">processHeaders</a>(<span class="keywordtype">int</span> <a class="code" href="my_obj_dump_8c.html#a6f8059414f0228f0256115e024eeed4b" title="Pointer to binary file.">fd</a>)
<a name="l00174"></a>00174 {
<a name="l00175"></a>00175 
<a name="l00176"></a>00176         Elf * e = 0;
<a name="l00177"></a>00177         Elf_Scn * scn;
<a name="l00178"></a>00178         GElf_Shdr shdr;
<a name="l00179"></a>00179         <span class="keywordtype">size_t</span> shstrndx;
<a name="l00180"></a>00180 
<a name="l00181"></a>00181         <a class="code" href="elf_process_8c.html#a309cc9f8f31dc406fbd4f950f14c9e85" title="Validate if the input file is an elf object.">validateElf</a>(&amp;e, fd, &amp;shstrndx);
<a name="l00182"></a>00182 
<a name="l00183"></a>00183         scn = NULL;
<a name="l00184"></a>00184 
<a name="l00185"></a>00185         <span class="keywordflow">while</span> ((scn = elf_nextscn(e, scn)) != NULL )
<a name="l00186"></a>00186         {
<a name="l00187"></a>00187                 <span class="keywordflow">if</span> (gelf_getshdr(scn, &amp;shdr) != &amp;shdr)
<a name="l00188"></a>00188                 {
<a name="l00189"></a>00189                         <a class="code" href="debug_8c.html#a8ded31085b483d44dbeb3adbecd2debf" title="Displays the error message.">PRINT_ERROR</a>(<span class="stringliteral">&quot;getshdr () failed : % s . &quot;</span>, elf_errmsg(-1));
<a name="l00190"></a>00190                         <span class="keywordflow">return</span> <a class="code" href="debug_8h.html#ae4a97f0d170bc8dc771aac6c4f38ad1d" title="Response code when a process was run efficiently.">STATUS_ERROR</a>;
<a name="l00191"></a>00191                 }
<a name="l00192"></a>00192 
<a name="l00193"></a>00193                 <a class="code" href="header_process_8c.html#a5de22d81fbbb97dc663c2b87c27a6f48">processHeader</a>(shdr, e, shstrndx, fd);
<a name="l00194"></a>00194         }
<a name="l00195"></a>00195 
<a name="l00196"></a>00196         <span class="keywordflow">return</span> <a class="code" href="debug_8h.html#ae56fdb340b23940f7a64ed2e37c1774a" title="Response code when a process has performed an error in its execution.">STATUS_SUCCESS</a>;
<a name="l00197"></a>00197 }
<a name="l00203"></a><a class="code" href="elf_process_8h.html#a349bf83f64825eff7c81cd30ce65bdca">00203</a> <span class="keywordtype">void</span> <a class="code" href="elf_process_8c.html#a349bf83f64825eff7c81cd30ce65bdca" title="Displays the ELF file characteristics established in its header.">ReadingELFExecutableHeader</a>(Elf *e, <span class="keywordtype">int</span> <a class="code" href="my_obj_dump_8c.html#a6f8059414f0228f0256115e024eeed4b" title="Pointer to binary file.">fd</a>)
<a name="l00204"></a>00204 {
<a name="l00205"></a>00205         GElf_Ehdr ehdr;
<a name="l00206"></a>00206         <span class="keywordtype">int</span> i;
<a name="l00207"></a>00207         <span class="comment">//char *id;</span>
<a name="l00208"></a>00208         <span class="comment">//char bytes[8];</span>
<a name="l00209"></a>00209         <span class="keywordtype">size_t</span> n;
<a name="l00210"></a>00210 
<a name="l00211"></a>00211         <span class="keywordflow">if</span> (gelf_getehdr(e, &amp;ehdr) == NULL )
<a name="l00212"></a>00212                 <a class="code" href="debug_8c.html#a8ded31085b483d44dbeb3adbecd2debf" title="Displays the error message.">PRINT_ERROR</a>(<span class="stringliteral">&quot; getehdr() failed : %s. &quot;</span>, elf_errmsg(-1));
<a name="l00213"></a>00213 <span class="comment">//gelf_getclass retrieves the ELF class of the object being examined. 32bits o 64bits</span>
<a name="l00214"></a>00214         <span class="keywordflow">if</span> ((i = gelf_getclass(e)) == ELFCLASSNONE)
<a name="l00215"></a>00215                 <a class="code" href="debug_8c.html#a8ded31085b483d44dbeb3adbecd2debf" title="Displays the error message.">PRINT_ERROR</a>(<span class="stringliteral">&quot; getclass() failed : %s. &quot;</span>, elf_errmsg(-1));
<a name="l00216"></a>00216         (void) printf(<span class="stringliteral">&quot;%d - bit ELF object \n &quot;</span>, i == ELFCLASS32 ? 32 : 64);
<a name="l00217"></a>00217 <span class="comment">//elf getident function to retrieve the contents of the e_ident[] array from the underlying file.</span>
<a name="l00218"></a>00218         <span class="comment">/*if ((id = elf_getident(e, NULL )) == NULL )</span>
<a name="l00219"></a>00219 <span class="comment">                PRINT_ERROR(&quot; getident() failed : %s.&quot;, elf_errmsg(-1));</span>
<a name="l00220"></a>00220 <span class="comment">        (void) printf(&quot; %3s e_ident [0..%1d ] %7s &quot;, &quot; &quot;, EI_ABIVERSION, &quot; &quot;);*/</span>
<a name="l00221"></a>00221 
<a name="l00222"></a>00222         <span class="comment">/*for (i = 0; i &lt;= EI_ABIVERSION; i++)</span>
<a name="l00223"></a>00223 <span class="comment">        {</span>
<a name="l00224"></a>00224 <span class="comment">                bytes[i] = (char) id[i];</span>
<a name="l00225"></a>00225 <span class="comment">                (void) printf(&quot; [ ’%s’ %x ] &quot;, bytes, id[i]);</span>
<a name="l00226"></a>00226 <span class="comment">        }*/</span>
<a name="l00227"></a>00227         (void) printf(<span class="stringliteral">&quot; \n &quot;</span>);
<a name="l00228"></a>00228         printf(<a class="code" href="elf_process_8c.html#aa669cc9790fbafeb364cbe10641c172d" title="Sets the output format screen attributes ELF header.">PRINT_FMT</a>, <span class="stringliteral">&quot;e_type&quot;</span>, (uintmax_t) ehdr.e_type);
<a name="l00229"></a>00229         printf(<a class="code" href="elf_process_8c.html#aa669cc9790fbafeb364cbe10641c172d" title="Sets the output format screen attributes ELF header.">PRINT_FMT</a>, <span class="stringliteral">&quot;e_machine&quot;</span>, (uintmax_t) ehdr.e_machine);
<a name="l00230"></a>00230         printf(<a class="code" href="elf_process_8c.html#aa669cc9790fbafeb364cbe10641c172d" title="Sets the output format screen attributes ELF header.">PRINT_FMT</a>, <span class="stringliteral">&quot;e_version&quot;</span>, (uintmax_t) ehdr.e_version);
<a name="l00231"></a>00231         printf(<a class="code" href="elf_process_8c.html#aa669cc9790fbafeb364cbe10641c172d" title="Sets the output format screen attributes ELF header.">PRINT_FMT</a>, <span class="stringliteral">&quot;e_entry&quot;</span>, (uintmax_t) ehdr.e_entry);
<a name="l00232"></a>00232         printf(<a class="code" href="elf_process_8c.html#aa669cc9790fbafeb364cbe10641c172d" title="Sets the output format screen attributes ELF header.">PRINT_FMT</a>, <span class="stringliteral">&quot;e_phoff&quot;</span>, (uintmax_t) ehdr.e_phoff);
<a name="l00233"></a>00233         printf(<a class="code" href="elf_process_8c.html#aa669cc9790fbafeb364cbe10641c172d" title="Sets the output format screen attributes ELF header.">PRINT_FMT</a>, <span class="stringliteral">&quot;e_shoff&quot;</span>, (uintmax_t) ehdr.e_shoff);
<a name="l00234"></a>00234         printf(<a class="code" href="elf_process_8c.html#aa669cc9790fbafeb364cbe10641c172d" title="Sets the output format screen attributes ELF header.">PRINT_FMT</a>, <span class="stringliteral">&quot;e_flags&quot;</span>, (uintmax_t) ehdr.e_flags);
<a name="l00235"></a>00235         printf(<a class="code" href="elf_process_8c.html#aa669cc9790fbafeb364cbe10641c172d" title="Sets the output format screen attributes ELF header.">PRINT_FMT</a>, <span class="stringliteral">&quot;e_ehsize&quot;</span>, (uintmax_t) ehdr.e_ehsize);
<a name="l00236"></a>00236         printf(<a class="code" href="elf_process_8c.html#aa669cc9790fbafeb364cbe10641c172d" title="Sets the output format screen attributes ELF header.">PRINT_FMT</a>, <span class="stringliteral">&quot;e_phentsize&quot;</span>, (uintmax_t) ehdr.e_phentsize);
<a name="l00237"></a>00237         printf(<a class="code" href="elf_process_8c.html#aa669cc9790fbafeb364cbe10641c172d" title="Sets the output format screen attributes ELF header.">PRINT_FMT</a>, <span class="stringliteral">&quot;e_shentsize&quot;</span>, (uintmax_t) ehdr.e_shentsize);
<a name="l00238"></a>00238         <span class="keywordflow">if</span> (elf_getshdrnum(e, &amp;n) != 0)
<a name="l00239"></a>00239                 <a class="code" href="debug_8c.html#a8ded31085b483d44dbeb3adbecd2debf" title="Displays the error message.">PRINT_ERROR</a>(<span class="stringliteral">&quot; getshdrnum() failed : %s.&quot;</span>, elf_errmsg(-1));
<a name="l00240"></a>00240         (void) printf(<a class="code" href="elf_process_8c.html#aa669cc9790fbafeb364cbe10641c172d" title="Sets the output format screen attributes ELF header.">PRINT_FMT</a>, <span class="stringliteral">&quot;(shnum)&quot;</span>, (uintmax_t) n);
<a name="l00241"></a>00241         <span class="keywordflow">if</span> (elf_getshdrstrndx(e, &amp;n) != 0)
<a name="l00242"></a>00242                 <a class="code" href="debug_8c.html#a8ded31085b483d44dbeb3adbecd2debf" title="Displays the error message.">PRINT_ERROR</a>(<span class="stringliteral">&quot; getshdrstrndx () failed : %s.&quot;</span>, elf_errmsg(-1));
<a name="l00243"></a>00243         (void) printf(<a class="code" href="elf_process_8c.html#aa669cc9790fbafeb364cbe10641c172d" title="Sets the output format screen attributes ELF header.">PRINT_FMT</a>, <span class="stringliteral">&quot;(shstrndx)&quot;</span>, (uintmax_t) n);
<a name="l00244"></a>00244         <span class="keywordflow">if</span> (elf_getphdrnum(e, &amp;n) != 0)
<a name="l00245"></a>00245                 <a class="code" href="debug_8c.html#a8ded31085b483d44dbeb3adbecd2debf" title="Displays the error message.">PRINT_ERROR</a>(<span class="stringliteral">&quot; getphdrnum() failed : %s.&quot;</span>, elf_errmsg(-1));
<a name="l00246"></a>00246         (void) printf(<a class="code" href="elf_process_8c.html#aa669cc9790fbafeb364cbe10641c172d" title="Sets the output format screen attributes ELF header.">PRINT_FMT</a>, <span class="stringliteral">&quot;(phnum)&quot;</span>, (uintmax_t) n);
<a name="l00247"></a>00247         <span class="comment">//( void ) elf_end(e);</span>
<a name="l00248"></a>00248 
<a name="l00249"></a>00249 }
</pre></div></div><!-- contents -->
</div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Data Structures</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Defines</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><a class="el" href="elf_process_8c.html">elfProcess.c</a>      </li>

    <li class="footer">Generated on Thu Oct 11 2012 12:28:10 for Dissasemble by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.6.1 </li>
   </ul>
 </div>


</body>
</html>
